<HTML> <!-- --------------- --------------- THE JAVASCRIPT COOKBOOK by Erica Sadun, webrx@mindspring.com J. Brook Monroe, mrprogguy@techie.com Copyright (c)1998 by Charles River Media. All Rights Reserved. This applet can only be re-used or modifed by license holders of the JavaScript Cookbook CD-ROM. Credit must be given in the source code and this copyright notice must be maintained. If you do not hold a license to the JavaScript Cookbook, you may NOT duplicate or modify this code for your own use. Use at your own risk. No warranty is given or implied of the suitability of this applet for any specific application. Neither Erica Sadun nor Charles River Media will be held responsible for any unwanted effects due to the use of this applet or any derivative. --> <HEAD> <TITLE> Pokerama Code </TITLE> </HEAD> <SCRIPT LANGUAGE="JavaScript"> <!-- var Suit = new Array('C','H','D','S'); var Name = new Array('','A','2','3','4','5','6','7','8','9','10','J','Q','K','A'); var board; var deck; var deckIdx; var curCard; /*------------------------------------------------------------------------------ | ------------------------------------------------------------------------------*/ function Card(suit,number) { this.suit = suit; this.number = number; } /*------------------------------------------------------------------------------ | ------------------------------------------------------------------------------*/ function CurrentCardName() { return curCard.number+curCard.suit; } /*------------------------------------------------------------------------------ | ------------------------------------------------------------------------------*/ function Shuffle() { if(parent.frames[0].document.open()) { parent.frames[0].document.writeln('<HTML><BODY BGCOLOR="#008000"><FONT FACE="Arial,Helvetica" SIZE="5" COLOR="#FFFFFF">Shuffling...</FONT></BODY></HTML>'); parent.frames[0].document.close(); } for(var i = 0; i < 39; i++) { var r1 = Math.floor(Math.random() * 52); var r2 = r1; while(r2 == r1) r2 = Math.floor(Math.random() * 52); var t = deck[r2]; deck[r2] = deck[r1]; deck[r1] = t; } deckIdx = 0; curCard = deck[deckIdx]; } /*------------------------------------------------------------------------------ | ------------------------------------------------------------------------------*/ function NewDeck() { var idx = 0; deck = new Array(); for(var suit = 0; suit < 4; suit++) { st = Suit[suit]; for(var i = 1; i <= 13; i++) { deck[idx++] = new Card(st,Name[i]); } } deckIdx = 0; } /*------------------------------------------------------------------------------ | ------------------------------------------------------------------------------*/ function Select(arg) { var i = parseInt(arg.charAt(0)); var j = parseInt(arg.charAt(1)); j += i * 5; if(board[j].charAt(0) == 'B') { board[j] = CurrentCardName(); curCard = deck[++deckIdx]; RedrawBoard(); } } /*------------------------------------------------------------------------------ | ------------------------------------------------------------------------------*/ function RedrawBoard() { if(parent.frames[0].document.open()) { parent.frames[0].document.writeln('<HTML><BODY BGCOLOR="#008000"><FONT FACE="Arial,Helvetica" COLOR="#FFFFFF" SIZE="5">POKERAMA</FONT><BR>'); parent.frames[0].document.writeln('<TABLE><TR><TD WIDTH=120 VALIGN="TOP"><FONT FACE="Arial,Helvetica" SIZE=2><b>Click on an empty card back to place the face-up card at that location. Try to build poker hands vertically and horizontally using the cards as they are dealt from the deck.<p>As an exercise for the user, find a way to add and display scoring.</b></FONT></TD><TD>'); var i = 0; for(var row = 0; row < 5; row++) { for(col = 0; col < 5; col++) { parent.frames[0].document.write('<A HREF="javascript:parent.frames[1].Select(\''+row+col+'\')"><IMG SRC="../GRAFX/CARDS/'+board[i++]+'.JPG" WIDTH=55 HEIGHT=79 BORDER=1></A>'); } if(i == 5 && deckIdx < 24) { var imgName = "../GRAFX/CARDS/"+CurrentCardName()+'.JPG' parent.frames[0].document.write(' <IMG SRC="'+imgName+'" WIDTH=55 HEIGHT=79 BORDER=0>'); } parent.frames[0].document.writeln('<BR>'); } parent.frames[0].document.writeln('</TD></TR></TABLE></BODY></HTML>'); parent.frames[0].document.close(); } } /*------------------------------------------------------------------------------ | ------------------------------------------------------------------------------*/ function Setup() { board = new Array(); for(var i = 0; i < 25; i++) board[i] = 'BK01'; NewDeck(); Shuffle(); RedrawBoard(); } //--> </SCRIPT> <BODY> <SCRIPT LANGUAGE="JavaScript"> Setup(); </SCRIPT> </BODY> </HTML>